package org.martin.snsrs.actions;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;
import org.martin.snsrs.beans.Activity;
import org.martin.snsrs.beans.Tags;
import org.martin.snsrs.daos.ActivityDao;
import org.martin.snsrs.daos.TagsDao;
import org.martin.snsrs.presentation.beans.ActivityBrief;
import org.martin.snsrs.services.ActivityServices;
import org.martin.snsrs.services.UserServices;

public class GetActivityByTag extends UserBase{
	private String sessionKey;
	
	private String tagName;
	
	private List<ActivityBrief> activities;
	
	private ActivityDao activityDao;
	
	private UserServices userServices;
	
	private TagsDao tagsDao;
	
	private boolean isValidate;
	
	private ActivityServices activityServices;
	
	public void validate(){
		isValidate = true;
		if(userServices.getUserBySessionKey(sessionKey) == null){
			status = "error";
			errorReason = "未知用户";
			isValidate = false;
			return;
		}
		Tags tags = tagsDao.getTagByName(tagName);
		if(tags == null){
			status = "error";
			errorReason = "未知标签";
			isValidate = false;
			return;
		}
	}
	
	public String execute() throws Exception{
		if(!isValidate)
			return ERROR;
		List<Activity> activities = activityDao.gteActivitiesByTag(tagName);
		this.activities = activityServices.getPresentationActivityBrief(activities);
		return SUCCESS;
	}

	public String getSessionKey() {
		return sessionKey;
	}

	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}

	public String getTagName() {
		return tagName;
	}

	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	@JSON(serialize=true)
	public List<ActivityBrief> getActivities() {
		return activities;
	}

	public void setActivities(List<ActivityBrief> activities) {
		this.activities = activities;
	}

	public ActivityDao getActivityDao() {
		return activityDao;
	}

	public void setActivityDao(ActivityDao activityDao) {
		this.activityDao = activityDao;
	}

	public UserServices getUserServices() {
		return userServices;
	}

	public void setUserServices(UserServices userServices) {
		this.userServices = userServices;
	}

	public TagsDao getTagsDao() {
		return tagsDao;
	}

	public void setTagsDao(TagsDao tagsDao) {
		this.tagsDao = tagsDao;
	}

	public ActivityServices getActivityServices() {
		return activityServices;
	}

	public void setActivityServices(ActivityServices activityServices) {
		this.activityServices = activityServices;
	}
}
